package com.jianan.mis.data.dao.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * <p>Title: cps</p>
 * 
 * <p>Copyright: Copyright (c) 2008</p> 
 *
 * <p>Company: www.goodbaby.com</p>
 *  
 * <p>Description:分页控制器</p>
 * 
 * @author lisky 时间 2008-4-15 上午11:42:06
 * @version 1.0
 */
public class PageControl implements Serializable {
	private static final long serialVersionUID = 1L;

	private int pageNo = 1; // 当前页码

	private int pageSize =10;//每页行数

	private int rowCount; // 总行数

	private int pageCount; // 总页数

	private boolean usePrevious;// 前一页是否能用

	private boolean useBehind;// 后一页是否能用

	private boolean usePage = true;// 是否分页
	
	private List pageData = new ArrayList();//页面中的数据

	public PageControl() {
	}

	public PageControl(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public PageControl(int pageNo,int pageSize) {
		this.pageSize = pageSize;
		this.pageNo = pageNo;
	}
	
	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		if (pageSize == 0) {// 0-->不分页
			usePage = false;
			pageCount = 1;
			pageNo = 1;
			usePrevious = false;
			useBehind = false;
		}
		this.pageSize = pageSize;
	}

	public int getRowCount() {
		return rowCount;
	}
	
	public int getStartOfPage(){
		return (getPageNo() - 1) * getPageSize();
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
		if (usePage) {
			pageCount = (rowCount % pageSize == 0) ? (rowCount / pageSize)
					: (rowCount / pageSize + 1);
			usePrevious = pageNo == 1 ? false : true;
			useBehind = pageNo == pageCount ? false : true;
			if(rowCount == 0){
				useBehind = false;
				usePrevious = false;
			}
		}
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public boolean isUsePrevious() {
		return usePrevious;
	}

	public void setUsePrevious(boolean usePrevious) {
		this.usePrevious = usePrevious;
	}

	public boolean isUseBehind() {
		return useBehind;
	}

	public void setUseBehind(boolean useBehind) {
		this.useBehind = useBehind;
	}

	public boolean isUsePage() {
		return usePage;
	}

	public void setUsePage(boolean usePage) {
		this.usePage = usePage;
	}

	public List getPageData() {
		return pageData;
	}

	public void setPageData(List pageData) {
		this.pageData = pageData;
	}

}
